﻿Imports ADOEntityKYC
Imports System.Data
Partial Class Form_KYC2T_02
    Inherits System.Web.UI.Page
    Dim KYCEntity As KYCEntities = New KYCEntities
    Dim ds As DataSet

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Response.AddHeader("Cache-control", "no-store, must-revalidate, private,no-cache")
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("Expires", "0")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ds = Session("ds")
        bindingData()
        userPrint()

        'Dim pageKey As RegistryKey = Registry.CurrentUser.OpenSubKey("software\microsoft\internet explorer\pagesetup", True)

        'pageKey.SetValue("footer", "")
        'pageKey.SetValue("header", "")
        ''pageKey.SetValue("margin_left", "")
        ''pageKey.SetValue("margin_top", "")
        'pageKey.Close()

        Response.Write("<script>")
        Response.Write("window.print()")
        Response.Write("</script>")

    End Sub

    Private Sub bindingData()

        Dim CUSTSEQ As Integer = Request.QueryString("CUSTSEQ")
        Dim KYCSEQ As Integer = Request.QueryString("KYCSEQ")
        Dim qryCust As Object

        If KYCSEQ = 0 Then
            qryCust = (From cust In KYCEntity.MCUSTOMER
                Join p In KYCEntity.MPREFIX On cust.THPREFIX Equals p.PREFIXCODE
               Join n In KYCEntity.MNATIONALITY On cust.NATIONALITY Equals n.NATIONCODE
               Group Join biz In KYCEntity.MBUSINESS On cust.BIZTYPE1 Equals biz.BIZCODE
               Into a = Group From leftA In a.DefaultIfEmpty
               Group Join incom1 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE1 Equals incom1.NATIONCODE
               Into aa = Group From leftAA In aa.DefaultIfEmpty
               Group Join incom2 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE2 Equals incom2.NATIONCODE
               Into b = Group From leftB In b.DefaultIfEmpty
               Group Join incom3 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE3 Equals incom3.NATIONCODE
               Into c = Group From leftC In c.DefaultIfEmpty
               Where cust.CUSTSEQ = CUSTSEQ
               Select cust, p.PREFIXTH, n.NATIONALITYNAME, incomes1 = leftAA.COUNTYNAME,
               leftA.BIZNAME, incomes2 = leftB.COUNTYNAME, incomes3 = leftC.COUNTYNAME).ToList

        Else
            qryCust = (From cust In KYCEntity.MCUSTOMER
                Join p In KYCEntity.MPREFIX On cust.THPREFIX Equals p.PREFIXCODE
               Join n In KYCEntity.MNATIONALITY On cust.NATIONALITY Equals n.NATIONCODE
               Group Join biz In KYCEntity.MBUSINESS On cust.BIZTYPE1 Equals biz.BIZCODE
               Into a = Group From leftA In a.DefaultIfEmpty
               Group Join incom1 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE1 Equals incom1.NATIONCODE
               Into aa = Group From leftAA In aa.DefaultIfEmpty
               Group Join incom2 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE2 Equals incom2.NATIONCODE
               Into b = Group From leftB In b.DefaultIfEmpty
               Group Join incom3 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE3 Equals incom3.NATIONCODE
               Into c = Group From leftC In c.DefaultIfEmpty
               Group Join kyc In (From tblKyc In KYCEntity.RKYC Where tblKyc.ANSWERTYPE = 4 Select tblKyc) On cust.CUSTSEQ Equals kyc.CUSTSEQ
               Into d = Group From leftD In d.DefaultIfEmpty
               Where cust.CUSTSEQ = CUSTSEQ And leftD.KYCSEQ = KYCSEQ
               Select cust, leftD, p.PREFIXTH, n.NATIONALITYNAME, incomes1 = leftAA.COUNTYNAME,
               leftA.BIZNAME, incomes2 = leftB.COUNTYNAME, incomes3 = leftC.COUNTYNAME).ToList
            'If qryCust(0).cust.ISANSWERSARALY = 1 Then
            '    Dim tempSalary As Double
            '    tempSalary = qryCust(0).cust.SALARYPERMONTH()
            '    lblSalary.Text = String.Format("{0:n}", tempSalary)

            'Else
            '    lblSalary.Text = "-"
            'End If
            Dim tempSalary As Double
            tempSalary = qryCust(0).cust.SALARYPERMONTH()
            lblSalary.Text = String.Format("{0:n}", tempSalary)

            If Not qryCust(0).leftD Is Nothing Then

                If qryCust(0).leftD.ANSWER101 = 0 Then
                    lblAns101.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER102 = 0 Then
                    lblAns102.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER103 = 0 Then
                    lblAns103.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER104 = 0 Then
                    lblAns104.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER105 = 0 Then
                    lblAns105.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER106 = 0 Then
                    lblAns106.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER107 = 0 Then
                    lblAns107.Text = "x"
                    lblAns199.Text = qryCust(0).leftD.ANSWER199
                End If


                If qryCust(0).leftD.ANSWER201 = 0 Then
                    lblAns201.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER202 = 0 Then
                    lblAns202.Text = "x"
                End If


                lblRef101.Text = qryCust(0).leftD.REF101
                lblRef102.Text = qryCust(0).leftD.REF102
                If Not qryCust(0).leftD.REF103 = Nothing Then
                    If qryCust(0).leftD.REF103 = 1 Then
                        lblRef1031.Text = "X"
                    ElseIf qryCust(0).leftD.REF103 = 2 Then
                        lblRef1032.Text = "X"
                    ElseIf qryCust(0).leftD.REF103 = 3 Then
                        lblRef1033.Text = "X"
                    ElseIf qryCust(0).leftD.REF103 = 4 Then
                        lblRef1034.Text = "X"
                    ElseIf qryCust(0).leftD.REF103 = 5 Then
                        lblRef1035.Text = "X"
                    ElseIf qryCust(0).leftD.REF103 = 99 Then
                        lblRef1036.Text = "X"
                    End If
                End If
                lblRef104.Text = qryCust(0).leftD.REF104

                lblRef201.Text = qryCust(0).leftD.REF201
                lblRef202.Text = qryCust(0).leftD.REF202
                If Not qryCust(0).leftD.REF203 = Nothing Then
                    If qryCust(0).leftD.REF203 = 1 Then
                        lblRef2031.Text = "X"
                    ElseIf qryCust(0).leftD.REF203 = 2 Then
                        lblRef2032.Text = "X"
                    ElseIf qryCust(0).leftD.REF203 = 3 Then
                        lblRef2033.Text = "X"
                    ElseIf qryCust(0).leftD.REF203 = 4 Then
                        lblRef2034.Text = "X"
                    ElseIf qryCust(0).leftD.REF203 = 5 Then
                        lblRef2035.Text = "X"
                    ElseIf qryCust(0).leftD.REF203 = 99 Then
                        lblRef2036.Text = "X"
                    End If
                End If
                lblRef204.Text = qryCust(0).leftD.REF204

                lblRef301.Text = qryCust(0).leftD.REF301
                lblRef302.Text = qryCust(0).leftD.REF302
                If Not qryCust(0).leftD.REF303 = Nothing Then
                    If qryCust(0).leftD.REF303 = 1 Then
                        lblRef3031.Text = "X"
                    ElseIf qryCust(0).leftD.REF303 = 2 Then
                        lblRef3032.Text = "X"
                    ElseIf qryCust(0).leftD.REF303 = 3 Then
                        lblRef3033.Text = "X"
                    ElseIf qryCust(0).leftD.REF303 = 4 Then
                        lblRef3034.Text = "X"
                    ElseIf qryCust(0).leftD.REF303 = 5 Then
                        lblRef3035.Text = "X"
                    ElseIf qryCust(0).leftD.REF303 = 99 Then
                        lblRef3036.Text = "X"
                    End If
                End If
                lblRef304.Text = qryCust(0).leftD.REF304

                lblAccountno.Text = qryCust(0).leftD.ACCOUNTNO
            End If

        End If
        


        If Not qryCust.Count = 0 Then

            If qryCust(0).cust.THPREFIX = 160 Then
                lblPrefix1.Text = "X"
            ElseIf qryCust(0).cust.THPREFIX = 161 Then
                lblPrefix2.Text = "X"
            ElseIf qryCust(0).cust.THPREFIX = 205 Then
                lblPrefix3.Text = "X"
                'ElseIf qryCust(0).cust.THPREFIX = 54 Then
                '    lblPrefix4.Text = "X" 'ยังไม่ครบ
            Else
                lblPrefix5.Text = "X"
                lblPrefixOther.Text = qryCust(0).PREFIXTH
            End If

            lblTHName.Text = qryCust(0).cust.THFIRSTNAME

            'lblENName.Text = qryCust(0).cust.ENFIRSTNAME.ToUpper
            If Not qryCust(0).cust.ENFIRSTNAME Is Nothing Then
                lblENName.Text = qryCust(0).cust.ENFIRSTNAME.ToUpper
            End If

            lblUniqueID.Text = qryCust(0).cust.UNIQUEID 
            If qryCust(0).cust.BIZTYPE1 = 99 Then
                lblBiz.Text = qryCust(0).cust.BIZTYPEOTHER1
            Else
                lblBiz.Text = qryCust(0).BIZNAME
            End If

            lblNational.Text = convertThai(qryCust(0).NATIONALITYNAME)

            lblIncome.Text = convertThai(qryCust(0).incomes1)
            If Not qryCust(0).cust.INCOMESOURCE2 Is Nothing Then
                lblIncome.Text += ", " + convertThai(qryCust(0).incomes2)
            End If
            If Not qryCust(0).cust.INCOMESOURCE3 Is Nothing Then
                lblIncome.Text += ", " + convertThai(qryCust(0).incomes3)
            End If

            If Not qryCust(0).cust.NGOCHECK1 Is Nothing Then
                If qryCust(0).cust.NGOCHECK1 = 1 Then
                    lblNPO1.Text = "X"
                ElseIf qryCust(0).cust.NGOCHECK1 = 2 Then
                    lblNPO2.Text = "X"
                End If
            End If

            If Not qryCust(0).cust.COMPCHECK1 Is Nothing Then
                If qryCust(0).cust.COMPCHECK1 = 1 Then
                    lblRegis1.Text = "X"
                ElseIf qryCust(0).cust.COMPCHECK1 = 2 Then
                    lblRegis2.Text = "X"
                ElseIf qryCust(0).cust.COMPCHECK1 = 3 Then
                    lblRegis3.Text = "X"
                End If
            End If


            lblFormalAddr.Text = qryCust(0).cust.FORMALADDR
            lblFormalPhone.Text = qryCust(0).cust.FORMALPHONE1


            If lblNational.Text = "ไทย" Then
                lblChkNation1.Text = "X"
                lblNational.Text = ""
            Else
                lblChkNation2.Text = "X"

            End If

            If lblIncome.Text = "ไทย" Then
                lblChkIncome1.Text = "X"
                lblIncome.Text = ""
            Else
                lblChkIncome2.Text = "X"
            End If

            If Not qryCust(0).cust.CHECKADDRESS Is Nothing Then

                If qryCust(0).cust.CHECKADDRESS = 22 Or qryCust(0).cust.CHECKADDRESS = 25 Then
                    lblEv1.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 23 Or qryCust(0).cust.CHECKADDRESS = 21 Then
                    lblEv2.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 29 Then
                    lblEv3.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 30 Then
                    lblEv4.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 31 Then
                    lblEv5.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 32 Then
                    lblEv6.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 33 Then
                    lblEv7.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 34 Then
                    lblEv8.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 35 Then
                    lblEv9.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 36 Then
                    lblEv10.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 37 Then
                    lblEv11.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 38 Then
                    lblEv12.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 39 Then
                    lblEv13.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 40 Then
                    lblEv14.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 41 Then
                    lblEv15.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 42 Then
                    lblEv16.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 43 Then
                    lblEv17.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 44 Then
                    lblEv18.Text = "X"
                Else
                    lblEv19.Text = "X"
                End If
            End If
            lblCustCode.Text = qryCust(0).cust.CUSTCODE
        End If


        qryCust = Nothing

    End Sub

    Private Sub userPrint()

        Dim convertDate As clsDateFormat = New clsDateFormat
        Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
        clsSessionMenuRight = Session("clsMenuRight")

        lblUserName.Text = clsSessionMenuRight.getEmpFirstName + "&nbsp;&nbsp;" + clsSessionMenuRight.getEmpLastName
        lblPrintDate.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
        lblUserID.Text = clsSessionMenuRight.getUserName
        lblBranch.Text = clsSessionMenuRight.getBranchName
        convertDate = Nothing
        clsSessionMenuRight = Nothing

    End Sub

    Private Function convertThai(ByVal country As String) As String
        Dim str As String = ""
        If country = "THAI" Or country = "THAILAND" Then
            str = "ไทย"
        Else
            str = country
        End If

        Return str
    End Function


End Class
